package com.xy.hms.service.imp;

import com.xy.hms.mapper.StaffMapper;
import com.xy.hms.model.Staff;
import com.xy.hms.service.StaffServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xiaye
 * @create 2020-03-16-14:55
 */
@Service
public class StaffServiceImp implements StaffServiceI {


    @Autowired
    StaffMapper staffMapper;

    @Override
    public Staff queryById(Integer id) {

        Staff staff = staffMapper.queryById(id);
        return staff;
    }

    /**
     * 查询所有的员工
     * @return
     */
    @Override
    public List<Staff> queryAll(Staff staff) {
        List<Staff> staffs = staffMapper.queryAll(staff);
        if (staffs.isEmpty()){
            //列表为空
            throw new RuntimeException("查询失败,暂未查到数据");
        }else{
            return staffs;
        }

    }

    @Override
    public String insert(Staff staff) {
        //插入员工数据
        int insert = staffMapper.insert(staff);
        if (insert!=0){  //插入成功
            return INSERT_SUCCESS;
        }else {
            throw new RuntimeException(INSERT_FAIL);
        }
    }

    @Override
    public String update(Staff staff) {
        //修改返回状态值
        int update = staffMapper.update(staff);

        if (update!=0){
            //修改成功
            return UPDATE_SUCCESS;
        }else {
            return UPDATE_FAIL;
        }

    }

    @Override
    public boolean deleteById(Integer id) {
        int i = staffMapper.deleteById(id);
        if (i!=0) return true;
        else return false;
    }
}
